import { createContext, useContext } from 'react'
import type { CheckListValue, CheckListProps } from './type'

export type CheckListContextType = Pick<CheckListProps, 'activeIcon' | 'disabled' | 'isLink' | 'readOnly' | 'extra'> & {
  /** 选中时触发. */
  check: (val: CheckListValue) => void
  /** 未选中时触发. */
  uncheck: (val: CheckListValue) => void
  /** 选中项. default: [] */
  value: CheckListValue[]
}

const CheckListContext = createContext<CheckListContextType | null>(null)

export const CheckListProvider = CheckListContext.Provider

export const useCheckList = (): CheckListContextType | null => useContext(CheckListContext)
